package xiaohongshu

import (
	"github.com/gin-gonic/gin"
	"go.uber.org/zap"
	"marketing-server/global"
	"marketing-server/model/common/response"
	"marketing-server/model/marketing/xiaohongshu"
	xiaohongshuReq "marketing-server/model/marketing/xiaohongshu/request"
)

type XhsTicketApi struct{}

// CreateXhsTicket 创建xhsTicket表
// @Tags XhsTicket
// @Summary 创建xhsTicket表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body marketing.XhsTicket true "创建xhsTicket表"
// @Success 200 {object} response.Response{msg=string} "创建成功"
// @Router /xhsTicket/createXhsTicket [post]
func (xhsTicketApi *XhsTicketApi) CreateXhsTicket(c *gin.Context) {
	var xhsTicket xiaohongshu.XhsTicket
	err := c.ShouldBindJSON(&xhsTicket)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	err = xhsTicketService.CreateXhsTicket(&xhsTicket)
	if err != nil {
		global.MS_LOG.Error("创建失败!", zap.Error(err))
		response.FailWithMessage("创建失败:"+err.Error(), c)
		return
	}
	response.OkWithMessage("创建成功", c)
}

// DeleteXhsTicket 删除xhsTicket表
// @Tags XhsTicket
// @Summary 删除xhsTicket表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body marketing.XhsTicket true "删除xhsTicket表"
// @Success 200 {object} response.Response{msg=string} "删除成功"
// @Router /xhsTicket/deleteXhsTicket [delete]
func (xhsTicketApi *XhsTicketApi) DeleteXhsTicket(c *gin.Context) {
	id := c.Query("id")
	err := xhsTicketService.DeleteXhsTicket(id)
	if err != nil {
		global.MS_LOG.Error("删除失败!", zap.Error(err))
		response.FailWithMessage("删除失败:"+err.Error(), c)
		return
	}
	response.OkWithMessage("删除成功", c)
}

// DeleteXhsTicketByIds 批量删除xhsTicket表
// @Tags XhsTicket
// @Summary 批量删除xhsTicket表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Success 200 {object} response.Response{msg=string} "批量删除成功"
// @Router /xhsTicket/deleteXhsTicketByIds [delete]
func (xhsTicketApi *XhsTicketApi) DeleteXhsTicketByIds(c *gin.Context) {
	ids := c.QueryArray("ids[]")
	err := xhsTicketService.DeleteXhsTicketByIds(ids)
	if err != nil {
		global.MS_LOG.Error("批量删除失败!", zap.Error(err))
		response.FailWithMessage("批量删除失败:"+err.Error(), c)
		return
	}
	response.OkWithMessage("批量删除成功", c)
}

// UpdateXhsTicket 更新xhsTicket表
// @Tags XhsTicket
// @Summary 更新xhsTicket表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body marketing.XhsTicket true "更新xhsTicket表"
// @Success 200 {object} response.Response{msg=string} "更新成功"
// @Router /xhsTicket/updateXhsTicket [put]
func (xhsTicketApi *XhsTicketApi) UpdateXhsTicket(c *gin.Context) {
	var xhsTicket xiaohongshu.XhsTicket
	err := c.ShouldBindJSON(&xhsTicket)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	err = xhsTicketService.UpdateXhsTicket(xhsTicket)
	if err != nil {
		global.MS_LOG.Error("更新失败!", zap.Error(err))
		response.FailWithMessage("更新失败:"+err.Error(), c)
		return
	}
	response.OkWithMessage("更新成功", c)
}

// FindXhsTicket 用id查询xhsTicket表
// @Tags XhsTicket
// @Summary 用id查询xhsTicket表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data query marketing.XhsTicket true "用id查询xhsTicket表"
// @Success 200 {object} response.Response{data=marketing.XhsTicket,msg=string} "查询成功"
// @Router /xhsTicket/findXhsTicket [get]
func (xhsTicketApi *XhsTicketApi) FindXhsTicket(c *gin.Context) {
	id := c.Query("id")
	rexhsTicket, err := xhsTicketService.GetXhsTicket(id)
	if err != nil {
		global.MS_LOG.Error("查询失败!", zap.Error(err))
		response.FailWithMessage("查询失败:"+err.Error(), c)
		return
	}
	response.OkWithData(rexhsTicket, c)
}

// GetXhsTicketList 分页获取xhsTicket表列表
// @Tags XhsTicket
// @Summary 分页获取xhsTicket表列表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data query marketingReq.XhsTicketSearch true "分页获取xhsTicket表列表"
// @Success 200 {object} response.Response{data=response.PageResult,msg=string} "获取成功"
// @Router /xhsTicket/getXhsTicketList [get]
func (xhsTicketApi *XhsTicketApi) GetXhsTicketList(c *gin.Context) {
	var pageInfo xiaohongshuReq.XhsTicketSearch
	err := c.ShouldBindQuery(&pageInfo)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	list, total, err := xhsTicketService.GetXhsTicketInfoList(pageInfo)
	if err != nil {
		global.MS_LOG.Error("获取失败!", zap.Error(err))
		response.FailWithMessage("获取失败:"+err.Error(), c)
		return
	}
	response.OkWithDetailed(response.PageResult{
		List:     list,
		Total:    total,
		Page:     pageInfo.Page,
		PageSize: pageInfo.PageSize,
	}, "获取成功", c)
}

// GetXhsTicketPublic 不需要鉴权的xhsTicket表接口
// @Tags XhsTicket
// @Summary 不需要鉴权的xhsTicket表接口
// @accept application/json
// @Produce application/json
// @Param data query marketingReq.XhsTicketSearch true "分页获取xhsTicket表列表"
// @Success 200 {object} response.Response{data=object,msg=string} "获取成功"
// @Router /xhsTicket/getXhsTicketPublic [get]
func (xhsTicketApi *XhsTicketApi) GetXhsTicketPublic(c *gin.Context) {
	// 此接口不需要鉴权
	// 示例为返回了一个固定的消息接口，一般本接口用于C端服务，需要自己实现业务逻辑
	xhsTicketService.GetXhsTicketPublic()
	response.OkWithDetailed(gin.H{
		"info": "不需要鉴权的xhsTicket表接口信息",
	}, "获取成功", c)
}
